/* when the page has finished loading.. execute the follow */
$(document).ready(function () {
    jQuery("#userList").jqGrid({
        url:'/user/listUsersAsJSON',
        datatype: "json",
        colNames:['ID', 'Username', 'First Name', 'Last Name', 'Email', 'Enabled', 'Notes'],
        colModel:[
            {name:'id', width:35},
            {name:'username', width:75},
            {name:'firstName', width:85},
            {name:'lastName', width:85},
            {name:'email', width:200},
            {name:'enabled', width:55},
            {name:'notes', width:300}
        ],
        altRows: true,
        autowidth: true,
        height: 332,
        message: 'The data is not available. Please refresh the screen.',
        pager: '#userListPager',
        rowList: [20, 50, 75, 100],
        rowNum: 20,
//        scroll: true,
        shrinkToFit: false,
        subGrid: false,
        viewrecords: true,
        onSelectRow: function(id) {
            window.location = "show/" + id
        }
    });
    jQuery("#userList").jqGrid('gridResize',{minWidth:339,minHeight:80, maxHeight:600});
});

var timeoutHnd;
var type;

function doSearch(ev) {
    if (timeoutHnd) {
        clearTimeout(timeoutHnd)
    }
    timeoutHnd = setTimeout(gridReload,500)
}

function gridReload() {
    var searchValue = jQuery("#userSearch").val();
    jQuery("#userList").jqGrid('setGridParam', {url:"listUsersAsJSON?searchValue=" + searchValue, page:1}).trigger("reloadGrid");
}
